package interview.huawei.myself.online1.v2;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @Author CandyWall
 * @Date 2022/3/13--11:31
 * @Description
 */
public class Producer extends Thread{
    private MessageQueue messageQueue;
    private String name;
    public Producer(String name, MessageQueue messageQueue) {
        super(name);
        this.name = name;
        this.messageQueue = messageQueue;
        start();
    }
    @Override
    public void run() {
        Random random = new Random();
        while (true) {
            int num = random.nextInt(100);
            if (num % 2 == 0) {
                messageQueue.putEvenNumber(num);
            } else {
                messageQueue.putOddNumber(num);
            }
            System.out.println(name + " 生产了 " + num);
            try {
                TimeUnit.MILLISECONDS.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
